package com.example.mapper;

import com.example.domain.dto.DiseaseDTO;
import com.example.domain.po.Disease;
import com.example.domain.po.Keyword;
import com.example.domain.vo.DiseaseVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface DiseaseMapper {

     List<Disease> list();

     @Select("select * from disease ")
    List<Disease> listAll();

    void addDisease(DiseaseDTO diseaseDTO);

    @Insert("insert into disease_item(pic, info, disease_id) VALUES (#{s},#{info},#{id})")
    void addTiem(@Param("s") String s, @Param("info") String info, @Param("id") Integer id);



    List<DiseaseVo> listPage(@Param("name") String name, @Param("category") String category);



    @Select("  SELECT DISTINCT d.id ,d.name ,d.doctor_id  doctorId ,d.type ,d.count ,d.price ,di.pic ,di.info ,di.id itemId , d.author ,d.category  FROM disease d, disease_item di   where d.id = di.disease_id and    d.id = #{id}")
    List<DiseaseVo> findById(Integer id);

    @Update("update disease_item set pic=#{s} , info =#{info}  where disease_id =#{id}")
    void updateTiem(@Param("s") String s, @Param("info") String info, @Param("id") Integer id);


    List<Map<String, Object>> listByName(String name);

    List<DiseaseVo> getById(Integer id);

    /**
     * 增加浏览量
     * @param id
     */
    @Update("update disease set " +
            "browse=browse+1 " +
            "where id=#{id}")
    void addBrowse(Integer id);

    @Select("select name,link from keyword ")
    Map<String, String>  findKey();

    @Select("select * from keyword")
    List<Keyword> keyList();

}
